package org.lora.log4j;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

/**
 *<p>Title:Log4jConfigListener</p>
 *<p>Desription:Log4j初始化监听器</p>
 * Create Time:2016年7月6日 下午12:46:50
 * @author Bladnir@outlook.com
 * <p>History:</p>
 * 2016年7月6日  Bladnir Create</br>
 */
public class Log4jConfigListener implements ServletContextListener {

	public static final String CONFIG_LOCATION_PARAM = "log4jConfigLocation";
	
	private static Logger logger = Log4jUtil.getSystemLogger();  

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		LogManager.shutdown();
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		
		String location = event.getServletContext().getInitParameter(CONFIG_LOCATION_PARAM);
		if (location != null) {
			location = event.getServletContext().getRealPath(location);
			DOMConfigurator.configure(location);
			logger.info("Log4j ConfigListener Load Success");
		}
	}

}
